<!DOCTYPE html>
<html>
  <head>
    <title>jQuery WeUI</title>
    <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">

<meta name="description" content="Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description.
">

<link rel="stylesheet" href="../dist/lib/weui.min.css">
<link rel="stylesheet" href="../dist/css/jquery-weui.css">
<link rel="stylesheet" href="css/demos.css">

  </head>
 
  <body ontouchstart>
  <form id="userInformation" method="post">
 	<div class="weui-cells weui-cells_form">
	  <div class="weui-cell">
	    <div class="weui-cell__hd"><label class="weui-label">姓名</label></div>
	    <div class="weui-cell__bd">
	      <input class="weui-input" type="text" placeholder="姓名" name="userName" disabled="false" id="userName">
	    </div>
	  </div>
	  <div class="weui-cell">
	    <div class="weui-cell__hd"><label class="weui-label">学号</label></div>
	    <div class="weui-cell__bd">
	      <input class="weui-input" type="text" placeholder="学号" name="code" disabled="false" id="code">
	    </div>
	  </div>
	  <div class="weui-cell">
	    <div class="weui-cell__hd"><label class="weui-label">学校</label></div>
	    <div class="weui-cell__bd">
	      <input class="weui-input" type="text" placeholder="学校" name="schoolName" disabled="false" id="schoolName">
	    </div>
	  </div>
	  <div class="weui-cell">
	    <div class="weui-cell__hd"><label class="weui-label">qq</label></div>
	    <div class="weui-cell__bd">
	      <input class="weui-input" type="number" pattern="[0-9]*" placeholder="请输入qq号" name="qq" id="qq">
	    </div>
	  </div>
	  <div class="weui-cell">
	    <div class="weui-cell__hd"><label class="weui-label">微信</label></div>
	    <div class="weui-cell__bd">
	      <input class="weui-input" type="text" placeholder="请输入微信号" name="weChat" id="weChat">
	    </div>
	  </div>
	  <div class="weui-cell">
	    <div class="weui-cell__hd"><label class="weui-label">Email</label></div>
	    <div class="weui-cell__bd">
	      <input class="weui-input" type="email" placeholder="Email" name="email" id="email">
	    </div>
	  </div>
	  <div class="weui-cell">
	    <div class="weui-cell__hd"><label class="weui-label">手机号</label></div>
	    <div class="weui-cell__bd">
	      <input class="weui-input" type="number" placeholder="手机号" name="tele" id="tele">
	    </div>
	  </div>
	  <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">毕业后城市</label></div>
        <div class="weui-cell__bd">
          <input class="weui-input" id="home-city" type="text" name="city">
        </div>
      </div>
      <label for="weuiAgree" class="weui-agree">
      <input id="weuiAgree" type="checkbox" class="weui-agree__checkbox">
      <span class="weui-agree__text">
       	 阅读并同意<a href="tiaokuan.html">《相关条款》</a>
      </span>
    </label>
    <br>
    <button type="button" class="weui-btn weui-btn_primary" id="savea">保    存</button>
	</div>
	 </form>
    <script src="../dist/lib/jquery-2.1.4.js"></script>
	<script src="../dist/lib/fastclick.js"></script>
	
<script>
  $(function() {
    FastClick.attach(document.body);
  });
</script>
<script src="../dist/js/jquery-weui.js"></script>
<script src="../dist/js/city-picker.min.js"></script>
<script src="js/jquery-form.js"></script>
<script>
$("#home-city").cityPicker({
    title: "选择城市",
    showDistrict: false,
    onChange: function (picker, values, displayValues) {
      console.log(values, displayValues);
    }
  });
$("#savea").click(function (){
	var raw=$.rawCitiesData;
	   
	var alumnus={};
	alumnus.qq=$("#qq").val();
	alumnus.weChat=$("#qq").val();
	alumnus.email=$("#email").val();
	
	var str=$("#home-city").val();
	var pc=str.split(' ');
	var province="";
	var city="";
    for(var i=0;i< raw.length;i++) {
      if(raw[i].name == pc[0]){
    	  province=raw[i].code;
    	  var sub=raw[i].sub;
    	  for(var j=0;j< sub.length;j++){
    		  if(sub[j].name==pc[1]){
    			  city=sub[j].code;
    		  }
    	  }
      }
    }
	alumnus.province=province;
	alumnus.city=city;
	$.ajax({
	   type: "POST",
	   data:alumnus,
	   url: "/XYL/alumnus/setAlumnu",
	   cache : false,  //禁用缓存
	   dataType: "json",
	   success: function(data) {
		   $.toast("保存成功", function() {
               //console.log('close');
             });
	   },
	   error: function(result){
		   $.toast("出错了！", "cancel", function(toast) {});
	   }
	});
});



$.ajax({
	type: "POST",
   url: '/XYL/alumnus/getAlumnu',
   cache : false,  //禁用缓存
   dataType: "json",
   success: function(data) {
	   $("#userName").val(data.userName);
	   $("#code").val(data.code);
	   $("#schoolName").val(data.schoolName);
	   $("#qq").val(data.qq);
	   $("#weChat").val(data.weChat);
	   $("#email").val(data.email);
	   $("#tele").val(data.tele);
	   
	   var raw=$.rawCitiesData;
	   var province="";
	   var city="";
	   for(var i=0;i< raw.length;i++) {
	      if(raw[i].code == data.province){
	    	  province=raw[i].name;
	    	  var sub=raw[i].sub;
	    	  for(var j=0;j< sub.length;j++){
	    		  if(sub[j].code==data.city){
	    			  city=sub[j].name;
	    		  }
	    	  }
	      }
	   }
	   $("#home-city").val(province+" "+city);
   },
   error: function(result){
	   $.toast("出错了！", "cancel", function(toast) {});
   }
});
</script>
   
  </body>
</html>
